package com.dragon.repository.domain.dto;

import com.baomidou.mybatisplus.annotation.TableField;
import com.dragon.common.util.BeanUtils;
import com.dragon.repository.entity.Loan;
import com.dragon.repository.entity.OtherFile;
import com.dragon.repository.entity.WorkflowJson;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * @author sy
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class LoanDTO {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "id")
    private Integer id;

    @ApiModelProperty(value = "用户id")
    private Integer adminId;

    @ApiModelProperty(value = "部门id")
    private Integer departmentId;

    @ApiModelProperty(value = "借款名称")
    private String loanName;

    @ApiModelProperty(value = "单据类型")
    private Integer loanType;

    @ApiModelProperty(value = "单据名称")
    private String expensesName;

    @ApiModelProperty(value = "借款金额")
    private BigDecimal loanMoney;

    @ApiModelProperty(value = "借款时间")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date loanTime;

    @ApiModelProperty(value = "合同id")
    private Integer contractId;

    @ApiModelProperty(value = "审核状态：0待审核 1审核通过 2审核不通过 3作废 4删除 ")
    private Integer status;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date updateTime;

    @ApiModelProperty(value = "备注")
    private String remark;

    @ApiModelProperty(value = "合同名称")
    private String contractName;

    @ApiModelProperty(value = "用户名称（申请人名称）")
    private String adminName;

    @ApiModelProperty(value = "部门名称")
    private String departmentName;

    @ApiModelProperty(value = "借款编号")
    private String num;

    @ApiModelProperty(value = "工作流json")
    private List<WorkflowJson> workflowJsonList;

    @ApiModelProperty(value = "借款附件")
    private List<OtherFile> otherFileList;

    @ApiModelProperty(value = "备用金金额")
    private Double spareMoney;


    public LoanDTO() {}

    public LoanDTO(Loan entity) {
        BeanUtils.copyProperties(entity,this);
    }

    public static LoanDTO convert(Loan entity) {
        return new LoanDTO(entity);
    }

    public static List<LoanDTO> convertList(List<Loan> list) {
        List<LoanDTO> resultList = new ArrayList<>();
        for (Loan entity : list) {
            resultList.add(new LoanDTO(entity));
        }
        return resultList;
    }}
